<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/jquery-weui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/index.css" />
		<link rel="stylesheet" type="text/css" href="../../css/order.css" />
		<link rel="stylesheet" type="text/css" href="https://at.alicdn.com/t/font_546019_o8qxm6fupb0ggb9.css" />
		<title>删除/修改物料</title>
		<script src="../../js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/baseConfig.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<style type="text/css">
	.handBtn {
			display: none;
			width: 100%;
			height: auto;
			overflow: hidden;
		}
		
		.handBtn .handBtnList p {
			width: 100%;
			padding: 0 5%;
			height: 2.5rem;
			line-height: 2.5rem;
			font-size: 0.65rem;
		}
		
		.handBtn .handBtnList p span {
			width: 11rem;
		}
		
		.handBtn .handBtnList p input {
			border: 1px solid #e2e2e2 !important;
			background-color:#fff;
			width: 3rem;
			font-size: 0.65rem !important;
			padding: 0.1rem 0.3rem;
			box-sizing: border-box;
		}
    
    
	</style>
	<body>
		<!--<div id="header">
			<div class="header-title" style="position: fixed;top: 0;">
				<img src="../../img/left.png" class="left" />
				<span>删除/修改物料</span>
			</div>
		</div>-->
		<div class="editMaterial" style="margin-top:0 ;">
			<p>
				<span>物料名称</span>
				<input type="" name="" id="" value="" class="materialName" disabled="disabled"/>
			</p>
			<p>
				<span>混合物料</span>
				<input type="" name="" id="" value="" class="isHunhe" disabled="disabled" />
			</p>
			<div class="handBtn">
			</div>
			<p>
				<span>物料重量量</span>
				<input type="" name="" id="" value="" class="materialNum" style="width: 9rem;"/>
				<em>吨</em>
			</p>
			<p>
				<span>物料单位</span>
				<input type="" name="" id="" value="" class="materialUnit"/>
				<em>元/吨</em>
			</p>
			<p>
				<span>含杂比例</span>
				<input type="" name="" id="" value="" class="proportion"/>
				<em>%</em>
			</p>
			<!--<p>
				<span>利润率</span>
				<input type="" name="" id="" value="" class="rate"/>
				<em>%</em>
			</p>-->
			<div class="demos-content-padded" style="margin-top: 1.5rem;">
				<a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary delete" style="float: left;margin-top: 0;background: #f65555;">删除</a>
				<a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary modify" style="float: right;margin-top: 0;background: #28c81e;">修改</a>	
			</div>
		</div>
		

	</body>
	<script type="text/javascript">
		$(document).ready(function() {
			baseConfig.historyBack()
			var materialName = baseConfig.GetQueryString("materialName");
			var weight = baseConfig.GetQueryString("weight");
			var id = baseConfig.GetQueryString("id");
			var unitPrice =  baseConfig.GetQueryString("unitPrice");
			var zazhiPercent = baseConfig.GetQueryString("zazhiPercent");
			var materialNo = baseConfig.GetQueryString("materialNo");
			var type = baseConfig.GetQueryString("type");
			$(".materialName").val(materialName);
			$(".materialNum").val(weight);
			$(".materialUnit").val(unitPrice);
			$(".proportion").val(zazhiPercent);
			var temp = "";
			var temp2 = "";
			var temp3 ="";
			
			$.ajax({
					type: "get",
					url: baseConfig.localHttp2+"api/order/getOrderFixMaterialList",
					async: false,
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded',
					},
					data: {
						id:id,
					},
					success: function(data) {
						console.log(data)
						if(data.code==100){
							if(data.content.length>=1){
								$(".isHunhe").val("是")
								$(".handBtn").show()
							}else{
								$(".isHunhe").val("否")
								$(".handBtn").hide()
							}
							
							var $div = "";
						for(var i = 0; i < data.content.length; i++) {
							temp += data.content[i].materialNo+","
							temp3 += data.content[i].id+","
							$div += "<div class='handBtnList'>"
							$div += "<p><span>"+data.content[i].materialName+"</span><input type='tel' value="+data.content[i].percent+" class='Num' maxlength='2' />%</p></div>"
						}
						$(".handBtn").empty()
						$(".handBtn").append($div)
//							location.href = "materialList.html?orderNo="+baseConfig.GetQueryString("orderNo")+"&orderid="+baseConfig.GetQueryString("orderid")
						}else{
							$(".isHunhe").val("否")
						}
					},
					error:function(){
						
					}
				})	
			$(".modify").on("click",function(){
				var mater = materialNo
				var counts = $(".materialNum").val();
				var unitPrice = $('.materialUnit').val();
				var zizhiPercent = $(".proportion").val();
				if($(".isHunhe").val("是")){
					for(var j = 0; j < $(".handBtnList p input").length; j++) {
						temp2 += $(".handBtnList p .Num").eq(j).val()+","
					}
				}			
				if(!mater || !counts || !unitPrice || !zizhiPercent){
					$.toptip("信息填写不全", 1200, 'error');
				}else{
					$.ajax({
					type: "get",
					url: baseConfig.localHttp2+"api/order/addOrEditMaterial",
					async: false,
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded',
					},
					data: {
						id:id,
						orderNo:baseConfig.GetQueryString("orderNo"),
						materialNo:mater,
						counts:counts,
						fixNo:temp,
						fixId:temp3,
						fixPercent:temp2,
						unitPrice:unitPrice,
						zizhiPercent:zizhiPercent,
					},
					success: function(data) {
						console.log(data)
						if(data.code==100){
							sessionStorage.removeItem("mater2")
							location.href = "materialList.html?orderNo="+baseConfig.GetQueryString("orderNo")+"&orderid="+baseConfig.GetQueryString("orderid")
						}else{
							
						}
					},
					error:function(){
						
					}
				})	
				}
				
			})
			$(".delete").on("click",function(){
				if(!sessionStorage.getItem("mater2")){
					var mater = materialNo
				}else{
					var mater = sessionStorage.getItem("mater2")
				}
				$.confirm("确定删除该物料？", function() {
				$.ajax({
					type: "get",
					url: baseConfig.localHttp2+"api/order/deleteMaterial",
					async: false,
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded',
					},
					data: {
						id:id,
						orderNo:baseConfig.GetQueryString("orderNo"),
					},
					success: function(data) {
						console.log(data)
						if(data.code==100){
							sessionStorage.removeItem("mater2")
							location.href = "materialList.html?orderNo="+baseConfig.GetQueryString("orderNo")+"&orderid="+baseConfig.GetQueryString("orderid")
						}else{
							
						}
					},
					error:function(){
						
					}
				})	
				},function(){
					
				})
			})
		})	
	</script>
</html>